package net.wds.ssbus.modules.ssbus.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import net.wds.ssbus.common.utils.R;
import net.wds.ssbus.modules.ssbus.pojo.TbSsbusChannelEntrty;
import net.wds.ssbus.modules.ssbus.pojo.TbSsbusRouteEntrty;
import net.wds.ssbus.modules.ssbus.pojo.TbSsbusTranslatorEntrty;
import net.wds.ssbus.modules.ssbus.service.TbSsbusChannelService;
import net.wds.ssbus.modules.ssbus.service.TbSsbusRouteService;
import net.wds.ssbus.modules.ssbus.service.TbSsbusTranslatorService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/tbssbusroute")
public class TbSsbusRouteController {
    /**
     * @author zl
     * @date 2020/10/31
     */
    @Resource
    private TbSsbusRouteService tbSsbusRouteService;

    @Resource
    private TbSsbusChannelService tbSsbusChannelService;

    @Resource
    private TbSsbusTranslatorService tbSsbusTranslatorService;

    /**
     *
     * @param key 查询条件
     * @param page 分页数量
     * @param limit 分页大小
     * @return
     */
    @GetMapping("/list")
    public R getList(@RequestParam(required=false) String key, @RequestParam(value="page",defaultValue="0")int page, @RequestParam(value="limit",defaultValue="5")int limit) {
        IPage<TbSsbusRouteEntrty> page1=tbSsbusRouteService.list(page,limit,key);
        return R.ok().put("page", page1);
    }

    /**
     *
     * @param tbSsbusRouteEntrty
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody TbSsbusRouteEntrty tbSsbusRouteEntrty) {
        tbSsbusRouteService.update(tbSsbusRouteEntrty);
        return R.ok();
    }

    /**
     *
     * @param tbSsbusRouteEntrty 保存路由
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody TbSsbusRouteEntrty tbSsbusRouteEntrty) {
        tbSsbusRouteService.save(tbSsbusRouteEntrty);
        return R.ok();
    }

    /**
     *
     * @return  获取通道列表
     */
    @GetMapping("getTbSsbusChannelList")
    public R getTbSsbusChannelList(){
        List<TbSsbusChannelEntrty> list= tbSsbusChannelService.getTbSsbusChannelList();
        return R.ok().put("list",list);
    }

    /**
     *
     * @return 获取转换器列表
     */
    @GetMapping("getTbSsbusTranslatorList")
    public R getTbSsbusTranslatorList(){
        List<TbSsbusTranslatorEntrty> list= tbSsbusTranslatorService.getTbSsbusTranslatorList();
        return R.ok().put("list",list);
    }

    /**
     *
     * @param id 根据id查询数据
     * @return
     */
    @GetMapping("/getById/{id}")
    public R getById(@PathVariable("id") Long id) {
        TbSsbusRouteEntrty tbSsbusRouteEntrty = tbSsbusRouteService.getById(id);
        return R.ok().put("data",tbSsbusRouteEntrty);
    }

    /**
     *
     * @param id 根据id删除
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        tbSsbusRouteService.removeById(id);
        return R.ok();
    }

    /**
     *
     * @param id 根据id批量删除
     * @return
     */
    @PostMapping("/deletes")
    public R deletes(@RequestBody Long id[]) {
        tbSsbusRouteService.deletes(id);
        return R.ok();
    }

}
